/*
 *  levelUpGame - AudioController.h
 *  Copyright 2011 W. Reckman. All rights reserved.
 */
#ifndef AUDIO_CONTROLLER_H
#define AUDIO_CONTROLLER_H

#include <map>
#include <vector>

class ofSoundPlayer;
class LevelUpApp;
class Settings;

class AudioController {
public:
	enum SOUNDS {
		SND_COUNTDOWN_START, SND_COUNTDOWN_END, SND_VOICE_GETREADY, SND_VOICE_GO,
		SND_VOICE_POSITIONS, SND_VOICE_3, SND_VOICE_2, SND_VOICE_1,
		SND_WIN, SND_DIE, SND_PICKUP_CULTURE,
		SND_PICKUP_INDUSTRY, SND_IDLE, SND_PLAYER_TURN, SND_PLAYER_ID
	};
	
	struct PlayerSounds {
		ofSoundPlayer* sndId;
		ofSoundPlayer* sndTurn;
	};
	
	typedef std::map<SOUNDS, ofSoundPlayer*> map_SOUNDS_ofSoundPlayerP;
	typedef std::vector<PlayerSounds> vec_PlayerSounds;
	
	
	AudioController( const LevelUpApp& appRef_ );
	~AudioController();
	
	void setup();
	void update();
	
	void play( SOUNDS snd_, int playerId_ = -1 );
	void stop( SOUNDS snd_, int playerId_ = -1 );
	
	void restartMusic();
	void setMusicVolume( float vol_ );
	bool isMusicMuted() const;
	void setMusicMuted( bool muted_ );
	
	void setLoop( SOUNDS snd_, bool loop_, int playerId_ = -1 );
	void setMultiPlay( SOUNDS snd_, bool mp_, int playerId_ = -1 );
	void setSpeed( SOUNDS snd_, float speed_, int playerId_ = -1 );
	void setPan( SOUNDS snd_, float pan_, int playerId_ = -1 );
	void setVolume( SOUNDS snd_, float vol_, int playerId_ = -1 );
	void setPosition( SOUNDS snd_, float pos_, int playerId_ = -1 );
	
	
private:
	static const float BALANCE_CHANGE_CENTER_DIST;
	
	const LevelUpApp& appRef;
	Settings& s;
	
	float xFadeDuration;
	bool musicMuted;
	float lastMusicVolume;
	float lastBalance;
	float xFadeStartTime;
	BALANCE_KIND xFadeDirection;
	
	map_SOUNDS_ofSoundPlayerP globalSounds;
	vec_PlayerSounds playerSounds;
	ofSoundPlayer musicIndustry, musicCulture;
	
	ofSoundPlayer* fetchSoundPlayer( SOUNDS snd_, int playerId_ );
	BALANCE_KIND balanceToKind( float balance_ ) const;
};

#endif /* !SOUND_CONTROLLER_H */
